package com.wngbms.gatewaydemo.filter;

import io.netty.handler.codec.http.FullHttpResponse;

public class AddResponseHeaderFilter implements HttpResponseFilter {

    private String key;
    private String value;
    private HttpResponseFilter nextFilter;

    public AddResponseHeaderFilter() {
    }

    public AddResponseHeaderFilter(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public AddResponseHeaderFilter(HttpResponseFilter nextFilter) {
        this.nextFilter = nextFilter;
    }

    @Override
    public void filter(FullHttpResponse response) {
        response.headers().add(key, value);

        if (nextFilter != null) {
            nextFilter.filter(response);
        }
    }

    public void setNextFilter(HttpResponseFilter nextFilter) {
        this.nextFilter = nextFilter;
    }
}
